const { network} = require("hardhat")
const { parseUnits } = require("ethers") // ethers v6


// constructor(uint96 _baseFee, uint96 _gasPrice, int256 _weiPerUnitLink), don't use BigInt, use ethers.js parseUnits instead
// const BASE_FEE = "2000000000000000" // 0.002 eth per gas, this is the premium fee for requesting randomness, calculated value based on the gas price of the chainlink node
// const GAS_PRICE = "40000000000"// 40 gwei, this is the gas price of the chainlink node, not the gas price of the transaction
// const WEi_PER_UNIT_LINK = "4000000000000000" // 0.004 eth per gas, this is the price of LINK in wei, calculated value based on the gas price of the chainlink node

const BASE_FEE = parseUnits("0.002", "ether").toString()
const GAS_PRICE = parseUnits("40", "gwei").toString()
const WEi_PER_UNIT_LINK = parseUnits("0.004", "ether").toString()

module.exports = async ({ deployments, getNamedAccounts }) => {
    const {deploy, log} = deployments
    const { deployer } = await getNamedAccounts()
    const chainId = network.config.chainId

    log("chainId:", chainId)
    log("deployer:", deployer)
    log("BASE_FEE:", BASE_FEE.toString())
    log("GAS_PRICE:", GAS_PRICE)
    log("WEi_PER_UNIT_LINK:", WEi_PER_UNIT_LINK.toString())
    log("----------------------------------------------------------")

    // If we are on a local development network, we need to deploy mocks!
    if (chainId == 31337) {
        log("Local network detected! Deploying mocks...")
        await deploy("VRFCoordinatorV2_5Mock", {
            from: deployer,
            log: true,
            args: [BASE_FEE, GAS_PRICE, WEi_PER_UNIT_LINK]
        })
        
        log("Mocks Deployed!")
        log("----------------------------------------------------------")
        log("You are deploying to a local network, you'll need a local network running to interact")
        log("Please run `yarn hardhat console --network localhost` to interact with the deployed smart contracts!")
        log("----------------------------------------------------------")
    }
}

module.exports.tags = ["all", "mocks"] 
